package main;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

import control.ControlCommand;
import control.DrawButton;
import control.Panel;
import control.TextControl;

public class HelpCanvas extends GameCanvas {

	protected Panel panel;
	protected TextControl textControl;
	protected final MainMidlet game;
	protected final String[] helps = new String[] {
			"   +How to play:\n\n"
					+ "Put the heroes on the map to\n prevent monsters moving to\nthe bottom of the map\n\n"
					+ "For each monster reaches the\nbottom, you lost a life. When\nyou run out of life,game over",
			"   +Fences:\n\n" + "You can put some fences to\nblock the way.",
			"   +Item:\n\n"
					+ "You can equip sword, bow,\narmor to the heroes.\n\n"
					+ "Buy a item from the store then\nsellect a hero to equip",
			"   +Hero's indicator\n\n" + "$(2) - attack\n" + "$(3) - defend\n"
					+ "$(4) - speed\n" + "$(5) - view range\n",
			"   +Item's indicator\n\n" 
					+ "Arm:\n" +
					"$(6) - damage\n" + "$(7) - attack range\n"
					+ "$(8) - delay between attacks\n(attack speed)\n\n" 
					+ "Suit:\n" +
					"$(9) - armor\n"

	};
	protected int currentHelp = 0;

	// protected Image background;

	protected HelpCanvas(MainMidlet midlet) {
		super(true);
		this.game = midlet;
		setFullScreenMode(true);
		textControl = new TextControl(helps[0], 30, 60);
		panel = new Panel(20, 20, 200, 360, 4);
		panel.setControl(0, textControl);
		panel.setControl(1, new DrawButton(-1, 160, 340, 60, 40, "BACK"));
		panel.get(1).setCommand(new ControlCommand() {
			public void Do() {
				game.showMenuCanvas();
			}
		});
		panel.setControl(2, new DrawButton(-1, 140, 20, 80, 30, "Next  >"));
		panel.get(2).setCommand(new ControlCommand() {
			public void Do() {
				currentHelp++;
				if (currentHelp == helps.length) {
					currentHelp = 0;
				}
				updateHelp();
			}
		});
		panel.setControl(3, new DrawButton(-1, 20, 20, 80, 30, "<Previous"));
		panel.get(3).setCommand(new ControlCommand() {
			public void Do() {
				currentHelp--;
				if (currentHelp < 0) {
					currentHelp = helps.length - 1;
				}
				updateHelp();
			}
		});
	}

	protected void updateHelp() {
		textControl.setText(helps[currentHelp]);
		// repaint();
	}

	protected void pointerPressed(int x, int y) {
		panel.pointerPressed(x, y);
		repaint();
	}

	protected void pointerReleased(int x, int y) {
		panel.pointerReleased(x, y);
		repaint();
	}

	protected void pointerDragged(int x, int y) {
		panel.pointerPressed(x, y);
		repaint();
	}

	public void paint(Graphics g) {
		// g.drawImage(background, 0, 0, 0);
		g.setColor(0x886600);
		g.fillRect(0, 0, 240, 400);
		panel.paint(g);
	}
}